#pragma once
#include "stdafx.h"
#include "DeviceContext.h"
#include "Effect.h"
#include "Texture.h"
#define DEVICE_DUMP_FILENAME "./log/device.txt"

class DeviceContext;
class Component;
class Texture;

class DeviceClass :public Component
{
private:
	DeviceClass();
	DeviceClass(const DeviceClass&);
	
public:
	typedef boost::shared_ptr<DeviceClass> sPtr;
	struct VideoCardInfo
	{
		VideoCardInfo(){};
		~VideoCardInfo() 
		{
		}
		DXGI_ADAPTER_DESC adapterDesc;
		Vector<DXGI_MODE_DESC> m_descriptions;
	};
	
	DeviceClass(bool,bool);
	~DeviceClass(void);
	unsigned int GetScreenWidth() const;
	unsigned int GetScreenHeight() const;
	bool CheckFeatures();
	void AddedToObject();
	
	ID3D11Device* GetDevice() const;

private:
	bool GetDeviceInfo();
	bool InitialDevice(HWND);
	void CreateInfoQueue();
	
	void Initialize(const Message& msg	);
	void CreateBuffer(const Message&);
	void CreateDepthStencilState(const Message&);
	void CreateInputLayout(const Message&);
	void CreatePixelShader(const Message&);
	void CreateRasterizerState(const Message&);
	void CreateTexture1D(const Message&);
	void CreateTexture2D(const Message&);
	void CreateTexture3D(const Message&);
	void CreateVertexShader(const Message&);
	void CompileShaderFromFile(const Message&);
	void CompileShaderFromFile(string, string, string,ID3DBlob** );
	void CreateEffect(const Message&);
	void Present(const Message&);
	void CreateTexture(const Message&);
	void CreateSamplerState(const Message&);
private:
	VideoCardInfo m_deviceInfo;
	ID3D11Device* m_device;
	IDXGISwapChain* m_swapChain;
	unsigned int m_screenHeight;
	unsigned int m_screenWidth;
	D3D_FEATURE_LEVEL m_feature;
	bool m_fullScreen;
	//XMMATRIX m_projectionMatrix;
	//XMMATRIX m_orthoMatrix;
	//XMMATRIX m_worldMatrix;
	fstream m_dumpFile;
	bool m_vsyncEnable;
	boost::shared_ptr<DeviceContext> m_deviceContext;
	DXGI_MODE_DESC m_activateModelDesc;
#ifdef _DEBUG
public:
	void DumpAllMessage(const Message&);
	string DetectError();
private:
	ID3D11Debug* m_debug;
	ID3D11InfoQueue* m_infoQueue;
#endif // _DEBUG

};

